//
// Created by benxb on 2022/3/14.
//

#ifndef BENXDB_DATA_CHUNK_POOL_H
#define BENXDB_DATA_CHUNK_POOL_H

#include <memory>
#include <unordered_map>
#include <deque>
#include "data_chunk.h"

namespace benxdb {

class DataChunkPool {
public:
    static std::shared_ptr<DataChunkPool> GetPool();

    /**
     * After use the chunk, it is need to call this function to recycle the data_ chunk
     * @param chunk_id
     */
    void UnPin(DataChunk* data_chunk);

    DataChunk* GetChunk();

private:
    DataChunkPool();

    static std::shared_ptr<DataChunkPool> instance_;

    static const int POOL_SIZE = 10;

    DataChunk chunks_[POOL_SIZE];

    // free data_ chunk
    std::deque<DataChunk*> free_chunk_list_;
};

}

#endif //BENXDB_DATA_CHUNK_POOL_H
